package com.zhq.boot;

import com.zhq.boot.bean.Cat;
import com.zhq.boot.bean.Dog;
import com.zhq.boot.bean.Pig;
import com.zhq.boot.bean.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @Project ：learn-spring-boot-3
 * @File ：MainApplication.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/3/27 10:52
 * @Description ：
 */

@SpringBootApplication  // 明确告诉这是一个springboot应用
public class MainApplication {

    public static void main(String[] args) {
        // java10的局部变量类型的自动推导
        var ioc = SpringApplication.run(MainApplication.class, args);

        // 获取容器中所有组件的名字
        /*
        String[] names = ioc.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
        */

        for (String s : ioc.getBeanNamesForType(Cat.class)) {
            System.out.println("Cat: " + s);
        }

        for (String s : ioc.getBeanNamesForType(Dog.class)) {
            System.out.println("Dog: " + s);
        }

        for (String s : ioc.getBeanNamesForType(User.class)) {
            System.out.println("user: " + s);
        }

        Pig pig = ioc.getBean(Pig.class);
        System.out.println("pig: " + pig);
    }
}
